<template>
  <div>
    <el-form :model="form" ref="shopForm" :rules="formRules" label-position="left" label-width="100px" class="demo-ruleForm login-container">
      <h3 class="title">店铺入驻</h3>
      <el-form-item prop="name"label="名称">
        <el-input type="text" v-model="form.name" auto-complete="off" placeholder="请输入店铺名称！"></el-input>
      </el-form-item>
      <el-form-item prop="tel" label="座机">
        <el-input type="text" v-model="form.tel" auto-complete="off" placeholder="请输入座机！"></el-input>
      </el-form-item>
      <el-form-item prop="address" label="店铺地址">
        <el-input type="text" style="width: 350px" v-model="form.address" auto-complete="off" placeholder="请输入地址！"></el-input>
        <!--        <el-button size="small" type="primary" @click="selectAdrress">选择</el-button>-->
      </el-form-item>
      <el-form-item prop="logo" label="店铺Logo">
        <img :src="imgSrc+form.logo" width="300" height="300" class="head_pic"/>
        <el-upload
            class="upload-demo"
            action="/api/dfs/upload"
            :on-remove="handleRemove"
            :on-success="handleSuccess"
            :file-list="fileList"
            list-type="picture">
          <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
        </el-upload>
      </el-form-item>
      <el-form-item style="width:100%;">
        <el-button type="primary" style="width:100%;" @click.native.prevent="settledIn" >修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<<script>
import {addUser, batchRemoveUser} from "../../api/api";
import util from "../../common/js/util";

export default {
  data(){
      return{
        imgSrc:"http://47.95.117.210:8888",
        formRules:false,
        fileList:[],
        form:{
          name:'',
          tel:"",
          address:"",
          logo:""
        }
    }
  },
  methods:{

    handleRemove(file, fileList) {
      var filePath =file.response.resultObj;
      this.$http.delete("/common/fastDfs/?path="+filePath)
          .then(res=>{
            if(res.data.success){
              this.$message({
                message: '删除成功!',
                type: 'success'
              });
            }else{
              this.$message({
                message: '删除失败!',
                type: 'error'
              });
            }
          })
    },
    handleSuccess(response, file, fileList){
      console.log("===========")
      console.log(response);
      console.log(file);
      console.log(fileList);
      this.form.logo = response.resultObj;
    },
    form(){

    },
    settledIn(row){
      this.addForm = Object.assign({},row);
      this.$http.put("/shop",this.form).then(res=>{
        let {success,message} = res.data;
        if (success){
          this.$message({
            message:"操作成功！！！",
            type:"success",
          });
          location.href="/http://127.0.0.1:8083/#/login"
        }else {
          this.$message.error("网络繁忙，请重试！！！")
        }
        //关闭模态框
        this.audit = false;
        this.listDateByShop();
      })
    },
    listDateByShop(){


     let id = location.href.split("=")[1]
      this.$http.get("/shop/"+id).then(res=>{
        this.form=res.data;
        console.log("!")
        console.log(this.form)
      })
    }
  },
  mounted() {
    this.listDateByShop();
  }
}
</script>

<style scoped>

</style>